home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Multimedia & Desktop / sk8 / SK8InJava / Code / Renderers / BevelRenderer.java next >
Encoding:
Java Source  |  1997-02-27  |  2.3 KB  |  83 lines  |  [TEXT/CWIE]

  1. /*  SK8 © 1997 Apple Computer, Inc.
  2.     This code is protected under the current SK8 License
  3.     See http://sk8.research.apple.com/ for more information
  4.     Apple Research Laboratories
  5. */
  6.  
  7.  
  8. import java.awt.*;
  9.  
  10. class bevelrenderer extends renderer {
  11.     
  12.     //Properties and their setters and getters
  13.     private rgbcolor leftrendererVar = sk8.graytone40;
  14.     private rgbcolor toprendererVar = sk8.graytone20;
  15.     private rgbcolor rightrendererVar = sk8.graytone70;
  16.     private rgbcolor bottomrendererVar = sk8.graytone90;
  17.     private int width = 5;
  18.     
  19.     public rgbcolor leftrenderer() { return leftrendererVar;}
  20.     public void setleftrenderer(rgbcolor val) { 
  21.         leftrendererVar = val;
  22.     }
  23.     public rgbcolor toprenderer() { return toprendererVar;}
  24.     public void settoprenderer(rgbcolor val) { 
  25.         toprendererVar = val;
  26.     }
  27.     public rgbcolor rightrenderer() { return rightrendererVar;}
  28.     public void setrightrenderer(rgbcolor val) { 
  29.         rightrendererVar = val;
  30.     }
  31.     public rgbcolor bottomrenderer() { return bottomrendererVar;}
  32.     public void setbottomrenderer(rgbcolor val) { 
  33.         bottomrendererVar = val;
  34.     }
  35.     
  36.     //Constructors
  37.     public bevelrenderer() {
  38.     
  39.     }
  40.     public bevelrenderer(rgbcolor leftrenderer, rgbcolor toprenderer, 
  41.                         rgbcolor rightrenderer, rgbcolor bottomrenderer) {
  42.         this.setleftrenderer(leftrenderer);
  43.         this.settoprenderer(toprenderer);
  44.         this.setrightrenderer(rightrenderer);
  45.         this.setbottomrenderer(bottomrenderer);
  46.     }
  47.     
  48.     void render(Graphics g, actor act, Region reg) {
  49.         Color currentColor;
  50.         Rectangle drawrect = reg.getBBox();
  51.         
  52.         //calculate the boundsrect points
  53.         int l = drawrect.x;
  54.         int t = drawrect.y;
  55.         int r = l + drawrect.width;
  56.         int b = t + drawrect.height;
  57.         //determine the size of the bevel piece
  58.         int count = (width < drawrect.width / 2)  ? width : drawrect.width/2;
  59.         count = (count < drawrect.height /2) ? count : drawrect.height/2;
  60.         
  61.         
  62.         // first, draw the sides as rectangles
  63.         g.setColor(leftrendererVar.currentColor);
  64.         g.fillRect(l, t, count, drawrect.height);
  65.         
  66.         g.setColor(rightrendererVar.currentColor);
  67.         g.fillRect(r - count, t, r, drawrect.height);
  68.         
  69.         
  70.         //then draw the top and the bottom diagonally going inward
  71.         for (; count > 0; count--){
  72.                         
  73.             g.setColor(toprendererVar.currentColor);
  74.             g.drawLine (l, t, r, t);
  75.                         
  76.             g.setColor(bottomrendererVar.currentColor);
  77.             g.drawLine (l, b, r, b);
  78.             
  79.             l++; r--;
  80.             t++; b--;
  81.         }
  82.     }
  83. }